package com.itheima.HomeWork;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Description Test1
 * @Author GreenHand_Lu
 * @Date 2025-07-20
 */
public class Test1 {

    public static void main(String[] args) {
        List< Order> orderList = new ArrayList<>();
        Order order = new Order();
        order.setOrderId("001");
        order.setOrderNo("2025072010000");
        order.setOrderTime("2025-07-20");
        order.setOrderItems(List.of(
                new OrderItem(1,"001","电脑",5000,1),
                new OrderItem(2, "001", "手机", 6666, 2)
                )
        );
        orderList.add( order);

        Order order2 = new Order();
        order2.setOrderId("002");
        order2.setOrderNo("2025072010001");
        order2.setOrderTime("2025-07-20");
        order2.setOrderItems(List.of(
                        new OrderItem(3,"002","西瓜",50,1),
                        new OrderItem(4, "002", "模型", 666, 2)
                )
        );
        orderList.add( order2);

        Iterator<Order> iterator = orderList.iterator();
        while (iterator.hasNext()){
            Order order3 = iterator.next();
            System.out.println("-----------------------------------------");
            System.out.println("订单号："+order3.getOrderId());
            System.out.println("下单时间："+order3.getOrderTime());
            System.out.println("订单项：");
            System.out.println("商品名字\t\t数量");
            Iterator<OrderItem> iterator2 = order3.getOrderItems().iterator();
            double totalMany = 0;
            while (iterator2.hasNext()){
                OrderItem orderItem = iterator2.next();
                System.out.println(orderItem.getGoodsName()+"\t\t"+orderItem.getNum());
                totalMany += orderItem.getNum()*orderItem.getPrice();
            }
            System.out.println("订单总金额："+totalMany);
            order3.setTotalMoney(totalMany);
        }


    }
}
